package cn.yuyin.item;

import javax.microedition.lcdui.Graphics;

import cn.yuyin.main.Main;
import cn.yuyin.page.ListForm;

public class Select extends Item{

	public ListForm listForm;
	public Select(int index,int x, int y, String text ,ListForm listForm) {
		super(x, y, text);
		this.index = index;
		this.listForm = listForm;
		width = Main.font.stringWidth(text)+2*Main.margin+20;
		if((x+width+30)>Main.WIDTH){
			width = Main.font.stringWidth(text)+2*Main.margin;
		}
		height = Main.font.getHeight()+4;
		endX = x+width;
		endY = y;
		listForm.select = this;
	}
	
	public Select(int index,int x, int y, String text ,Select select,ListForm listForm) {
		super(x, y, text);
		this.index = index;
		this.listForm = listForm;
		width = Main.font.stringWidth(text)+2*Main.margin+20;
		height = Main.font.getHeight()+4;
		endX = x+width;
		endY = y;
		listForm.select = this;
		listForm.select2 = select;
	}

	public Select(int index,int x, int y, String text ,ListForm listForm,int width) {
		super(x, y, text);
		this.index = index;
		this.listForm = listForm;
		this.width=width;
		height = Main.font.getHeight()+4;
		endX = x+width;
		endY = y;
		listForm.select = this;
	}
	
	public void paint(Graphics g) {
		if(index == Main.superPage.index){
			ishaveFouse = true;
		}else{
			ishaveFouse = false;
		}
		if(ishaveFouse){			
			
			g.setColor(0);
			g.drawString(text, x+Main.margin, y+2, 0);
			
			if(Main.font.stringWidth(text)>width){
				g.setColor(0xF2F5F8);
				g.fillRect(x+width, y, width, height);
			}  
			
			g.setColor(0xff0000);
			g.drawRect(x+width+5, y, 25, height);
			
			g.setColor(0xABBEFA);
			g.drawRect(x, y, width, height);
		
			
			g.setColor(0);
			g.fillTriangle(x+width+12, y+5, x+width+22, y+5, x+width+17, y+12);
			
		}else{
			g.setColor(0);
			g.drawString(text, x+Main.margin, y+2, 0);
			
			if(Main.font.stringWidth(text)>width){
				g.setColor(0xF2F5F8);
				g.fillRect(x+width, y, width, height);
			}  
			
			g.setColor(0xABBEFA);
			g.drawRect(x, y, width, height);
	
			g.setColor(0xABBEFA);
			g.drawRect(x+width+5, y, 25, height);	
			
			
			g.setColor(0);
			g.fillTriangle(x+width+12, y+5, x+width+22, y+5, x+width+17, y+12);
			
		}
	}

	public void keyPressed(int keyCode) {
		// TODO Auto-generated method stub
		
	}

	public void keyReleased(int keyCode) {
		switch (keyCode) {
		case Main.key_OK:
			if(ishaveFouse){
				
				Main.display.setCurrent(listForm);
			}
			break;
		}
	}

	public void pointerPressed(int x, int y) {
		Main.display.setCurrent(listForm);		
	}

	public void pointerReleased(int x, int y) {
		
	}

}
